from leapp.actors import Actor
from leapp.libraries.common.rpms import has_package
from leapp.models import InstalledRPM
from leapp.reporting import Report, create_report
from leapp import reporting
from leapp.reporting import create_report
from leapp.tags import ChecksPhaseTag, IPUWorkflowTag


class Checkopenssl11libs(Actor):
    """
    Check if openssl11-libs is installed. If yes, stop upgrade
    """

    name = 'check-openssl11-libs'
    consumes = (InstalledRPM,)
    produces = (Report,)
    tags = (ChecksPhaseTag, IPUWorkflowTag)

    def process(self):
        if has_package(InstalledRPM, 'openssl11-libs'):
            create_report([
                reporting.Title('Openssl11-libs is installed, openssl11-libs cannot be processed during upgrade.'),
                reporting.Summary(
                    'Package openssl11-libs is conflicated with openssl-libs from Anolis OS 8 while upgrading.\n'
                    'You should first backup your application files and data when your app requires openssl11-libs. Secondly, remove openssl11-libs from your OS and finally exec upgrade.'),
                reporting.Severity(reporting.Severity.HIGH),
                reporting.Remediation(hint='Please uninstall openssl11-libs, and then preupgrade again.'),
                reporting.Flags([reporting.Flags.INHIBITOR])
            ])
